import Vue from 'vue'
import Router from 'vue-router'
import LoginService from './../service/Login-service'
Vue.use(Router)

const Common = (resolve) => {
  import('@/components/Common').then((m) => {
    resolve(m)
  })
};
//聊天界面
const ChatPage = (resolve) => {
  import('@/view/ChatPage/chatPage').then((m) => {
    resolve(m)
  })
};
//询价
const Inquiry = (resolve) => {
  import('@/view/inquiry/inquiry').then((m) => {
    resolve(m)
  })
};
const Offer = (resolve) => {
  import('@/view/offer/offer').then((m) => {
    resolve(m)
  })
};
const FixCode = (resolve) => {
  import('@/view/fixCode/fixCode').then((m) => {
    resolve(m)
  })
};
//模块
const Module = (resolve) =>{
  import('@/components/module').then((m) => {
    resolve(m)
  })
};
//待定码列表
const WaitCode = (resolve) => {
  import('@/view/codeList/waitCode').then((m) => {
    resolve(m)
  })
};
//已定码列表
const FinishCode = (resolve) => {
  import('@/view/codeList/finishCode').then((m) => {
    resolve(m)
  })
};
//代客下询价单
const ReplaceInquire = (resolve) =>{
  import('@/view/customerManage/replaceInquire').then((m) => {
    resolve(m)
  })
}

//代客下订单
const OrderInfoProxy = (resolve) =>{
  import('@/view/customerManage/orderInfoProxy').then((m) => {
    resolve(m)
  })
};
//登录界面
const Login = (resolve)=>{
  import('@/view/system/login').then((m) => {
    resolve(m)
  })
}

const router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/app/ChatPage'
    },
    {
      path: '/system/login',
      name:'登录界面',
      component: Login
    },
    {
      path: '/app',
      component: Common,
      children:[
          {
            path: '/app/module',
            name: 'module',
            component: Module,
            children:[
              {
                path: '/app/module/waitCode',
                name: '待定码列表',
                component: WaitCode,
              },
              {
                path: '/app/module/finishCode',
                name: '已定码列表',
                component: FinishCode,
              },
              {
                path: '/app/module/replaceInquire',
                name: '代客下询价',
                component: ReplaceInquire,
              },
              {
                path: '/app/module/orderInfoProxy',
                name: '代客下订单',
                component: OrderInfoProxy,
              }
            ]
         },
        {
          path: '/app/chatPage',
          name: 'ChatPage',
          component : ChatPage,
          children : [
            {
              path: '/app/chatPage/inquiry',
              name: 'Inquiry',
              component: Inquiry,
            },
            {
              path: '/app/chatPage/offer',
              name: 'Offer',
              component: Offer,
            },
            {
              path: '/app/chatPage/fixCode',
              name: 'FixCode',
              component: FixCode,
            },
          ]
        },
      ]
    }
  ]
})
router.beforeEach((to, from, next) => {
  if(to.path === '/system/login'){
    next();
  }else{
    next()
   /* LoginService.getToken(()=>{
      next()
    })*/
  }

});

export default router
